<template>
  <div class="shareList">
    <div class="topFixed">
      <nav-com
        :title="title"
        :showView="showView"
        @back="backHandler()"
      ></nav-com>
      <div class="topbanner" @click.stop="toShare()">
        <img src="@/assets/friendShare/friendShareImg.png" />
      </div>
      <div class="list-toptab">
          <div
            class="tab-item"
            :class="tabIndex == 0 ? 'active' : ''"
            @click="changeTab(0)"
          >
            已领取信息
            <div class="tab-line"></div>
          </div>
          <div
            class="tab-item"
            :class="tabIndex == 1 ? 'active' : ''"
            @click="changeTab(1)"
          >
            好友分享
            <div class="tab-line"></div>
          </div>
      </div>
    </div>
    <div class="box-content">
      <div class="list-box" v-if="tabIndex == 0">
          <div class="top-bar">
              <div class="bar-tab" >
                  <div class="num">{{resData.share_count}}</div>
                  <div class="text">分享次数</div>
              </div>
              <div class="bar-tab" >
                  <div class="num">{{resData.share_goods_count}}</div>
                  <div class="text">分享商品</div>
              </div>
              <div class="bar-tab" >
                  <div class="num">{{resData.receive_sum}}</div>
                  <div class="text">已领取数量</div>
              </div>
              <div class="bar-tab" >
                  <div class="num">{{resData.noReceive_sum}}</div>
                  <div class="text">未领取数量</div>
              </div>
          </div>
          <div class="bottom-list">
                <div class="list-goods" v-for="(item,index) in resData.goods_list" :key="index" @click="toshareInfo(item)">
                    <div class="box1">时间：{{item.qr_time}}</div>
                    <div class="box2">
                        <div class="goods-tu">
                        <img :src="item.goods_img" />
                        </div>
                        <div class="goods-info">
                            <div class="name">
                              <div class="t0">{{item.goods_title}}</div>
                              <div class="t1">¥{{item.goods_price}}</div>
                            </div>
                            <div class="num">{{item.q_num}}</div>
                            <div class="statis">统计：已领取 {{item.num}} /未领取 {{item.no_num}}</div>
                       </div>
                </div>
              </div>
          </div>
      </div>
      <div class="list-content" v-if="tabIndex == 1">
        <div class="left-tab">
          <div
            class="left-tab-item"
            :class="lefttab == i ? 'leftactive' : ''"
            v-for="(item,i) in lefttabList"
            :key="i"
            @click="clickleftTab(i)"
          >
            {{item}}
          </div>
        </div>
        <div class="right-list">
          <div class="list-goods" v-for="(item,i) in list[lefttab]" :key="i" @click="togoodsDetail(item)">
            <div class="goods-tu">
              <img :src="item.image" />
            </div>
            <div class="goods-info">
              <div class="name">
                {{item.title}}
              </div>
              <div class="price-share">
                <div class="price">¥{{item.price}}</div>
                <div class="sharenum">已分享{{item.share_num}}份</div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { totalStatistics,friendgoodslist,userInfo5G,conversionUser } from "@/api/api";
import navCom from "@/component/nav";
export default {
  name: "bonusList",
  components: {
    navCom,
  },
  data() {
    return {
      showView: true,
      uid: weixin.getUserId(),
      title: "好友分享",
      listEmpty: "",

      resData:{},
      tabIndex: 0,
      lefttab: 0,
      lefttabList:[],
      list: [],
      userInfo:''
    };
  },
  mounted() {
    this.init();
    userInfo5G({token5g:localStorage.getItem("token5g")}).then(res=>{
      this.userInfo = res.data.data
      console.log("userInfo",this.userInfo)
      this.getGoodslist()
    })
  },
  methods: {
    //返回
    backHandler() {
      if (weixin.isAndroid()&&window.JS_TROOPS) {
        window.JS_TROOPS.goBack();
      } else {
        this.$router.go(-1);
      }
    },
    //初始化
    init() {
      totalStatistics({
        uid:weixin.getUserId(),
        page:1,
        limit:15
      }).then((res) => {
        if (res.data.code == 1) {
          this.resData=res.data.data
        }
      });
    },
    getGoodslist(){
      friendgoodslist({
        uid:weixin.getUserId(),
        page:1,
        limit:15,
        shop_id: this.userInfo.shop_id
      }).then((res) => {
        if (res.data.code == 1) {
          this.lefttabList=this.getObjectKeys(res.data.data)
          this.list=this.getObjectValues(res.data.data)
          console.log("this.list",this.list)
        }
      });
    },
    getObjectKeys(object)
    {
        var keys = [];
        for (var property in object)
          keys.push(property);
        return keys;
      },
    getObjectValues(object)
    {
        var values = [];
        for (var property in object)
          values.push(object[property]);
        return values;
      },
    changeTab(index) {
          this.tabIndex = index;
    },
    clickleftTab(index) {
          this.lefttab = index;
    },
    toshareInfo(item){
      localStorage.setItem("shareInfo",JSON.stringify(item))
      this.$router.push({
          name: "shareInfo",
          params:item,
        });
    },
    togoodsDetail(item){
      this.$router.push({
          name: "sharegoodDetails",
          params: {id: item.id},
        });
    },
    toShare(){
      this.$router.push({
        name: "inviteFriends",
      });
    }
  },
};
</script>
<style scoped>
.shareList {
  background: #f8f8f8;
}
.topFixed{
   background: #f8f8f8;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10;
}
.topbanner {
  width: 100%;
  height: 20vh;
}
.topbanner img {
  width: 100%;
  height: 20vh;
}
.box-content {
  min-height: 80vh;
  background: #ffffff;
  margin-top: 39vh;
}
.list-toptab {
  margin-top: 11px;
  background: #ffffff;
  box-shadow: 0px 2px 10px 0px rgb(0 0 0 / 5%);
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  display: flex;
  line-height: 8vh;
  border-bottom: 1px solid #e7e7e7;
}
.list-toptab .tab-item {
  flex: 1;
  font-size: 13px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #000000;
  text-align: center;
}
.list-toptab .tab-item.active {
  font-size: 14px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 550;
  color: #fa2c1e;
}
.list-toptab .tab-item.active .tab-line {
  width: 16px;
  height: 3px;
  background: #fa2c1e;
  border-radius: 2px;
  margin-left: calc(50% - 8px);
}
.list-content {
  display: flex;
  padding-top: 15px;
}
.left-tab {
  width: 80px;
  text-align: center;
  position: fixed;
    left: 0;
}
.left-tab-item {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #333333;
  line-height: 20px;
  margin-bottom: 30px;
}
.left-tab-item.leftactive {
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #fa2c1e;
  line-height: 22px;
}
.left-tab-item:first-child {
  margin-top: 15px;
}
.right-list {
  flex: 1;
  margin-left: 80px;
}
.right-list .list-goods {
  background: #f8f8f8;
  border-radius: 8px;
  display: flex;
  margin: 0 12px 12px 0;
  padding: 10px 8px;
}
.right-list .list-goods .goods-tu {
  width: 64px;
  height: 64px;
  margin-right: 8px;
}
.right-list .list-goods .goods-tu img {
  width: 64px;
  height: 64px;
  border-radius: 8px;
}
.right-list .list-goods .goods-info{flex:1}
.goods-info .name {
  font-size: 13px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #222222;
  line-height: 18px;
  max-height: 36px;
  margin-bottom: 13px;
  text-overflow: -o-ellipsis-lastline;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
}
.right-list .list-goods .goods-info .price-share {
  display: flex;
  justify-content: space-between;
}
.right-list .list-goods .goods-info .price-share .price {
  font-size: 16px;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #fa2c1e;
  line-height: 22px;
}
.right-list .list-goods .goods-info .price-share .sharenum {
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #999999;
  line-height: 17px;
}
/* 已领取信息样式 */
.list-box .top-bar{
  margin: 14px 8px 0;
  background: #FFFFFF;
  box-shadow: 0px 1px 10px 0px rgba(0,0,0,0.05);
  border-radius: 8px;
  display: flex;
  padding: 20px 4px;
}
.list-box .top-bar .bar-tab{
  flex: 1;
  text-align: center;
  position: relative;
}
.list-box .top-bar .bar-tab:not(:last-child) ::after{
   position: absolute;
   right: 0;
   top: 10px;
   content: '';
   width: 2px;
   height: 30px;
   background: #D1D2D5;
}
.list-box .top-bar .bar-tab .num{
  font-size: 14px;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 550;
color: #FA2C1E;
line-height: 26px;
}
.list-box .top-bar .bar-tab .text{
  font-size: 14px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 550;
color: #000000;
line-height: 20px;
}
.bottom-list .list-goods{
  background: #FFFFFF;
  box-shadow: 0px 1px 10px 0px rgba(0,0,0,0.05);
  border-radius: 8px;
  margin: 10px 8px 0;
  padding: 12px;
  display: flex;
    flex-direction: column;
}
.bottom-list .list-goods .box1{
  font-size: 12px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
line-height: 18px;
padding-bottom:8px;
border-bottom: 1px solid #E7E7E7;
}
.bottom-list .list-goods .box2{
  clear: both;
  display: flex;
  padding-top: 10px;
}
.bottom-list .list-goods .box2 .goods-tu{
  width: 64px;
  height: 64px;
  margin-right: 6px;
  border-radius: 6px;
}
.bottom-list .list-goods .box2 .goods-tu img{
  width: 100%;
  height: 100%;
  border-radius: 6px;
}
.bottom-list .list-goods .box2 .goods-info{
  flex:1
}
.box2 .goods-info .name{
  font-size: 13px;
font-family: PingFangSC-Medium, PingFang SC;
font-weight: 500;
color: #222222;
line-height: 18px;
margin-bottom:0;
display: flex;
justify-content: space-between;
}
.box2 .goods-info .name .t0{
  text-overflow: -o-ellipsis-lastline;
	overflow: hidden;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-line-clamp: 2;
	line-clamp: 2;
	-webkit-box-orient: vertical;
}
.box2 .goods-info .num{
  font-size: 13px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
line-height: 20px;
}
.box2 .goods-info .statis{
  font-size: 13px;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: #999999;
line-height: 20px;
}
</style>
